package com.apobates.jforum.grief.aurl.utils.defend;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
/**
 * 单值Assertion
 * 注意: 一个目标有多条消息, 遇到第一个失败规则后将收集未校验的失败消息
 * @param <T> 目标类型
 */
public class SingleCompleteAssertion<T> extends SingleAssertion<T> {
    protected SingleCompleteAssertion(Supplier<T> value) {
        super(value);
    }

    @Override
    public List<AssertResult<T>> asserte(PredicateQueue<T> predicateQueue) {
        List<AssertResult<T>> data = new ArrayList<>();
        boolean hasError=false;
        for (AssertPredicate<T> condition: predicateQueue.getConditions()) {
            if(!hasError) {
                if (!condition.predicate(getValue())) {
                    data.add(new AssertResult(getValue(), false, condition.getError(), 0, condition.getLabel()));
                    hasError = true;
                }
            } else{
                data.add(new AssertResult(getValue(), false, condition.getError(), 0, condition.getLabel()));
            }
        }
        return data;
    }
}
